axios({
    method: "GET",
    url: "http://127.0.0.1:8400/order",
}).then(response => {
    let count = 0;
    let money = 0;
    $.each(response.data, function(index, item) {
        if (item.state == "未付款") {
            count++;
            money = Number(money) + Number(item.price)
            $("#order_group_item").append(` 
        <div class="clearfix order_info" data-reactid=".0.2.2.0.1:$0.0.0.1.$0">
        <div class="fl relative" style="width:450px;padding:16px 0;line-height:21px;" data-reactid=".0.2.2.0.1:$0.0.0.1.$0.0">
        <div data-reactid=".0.2.2.0.1:$0.0.0.1.$0.0.0">
        <div data-reactid=".0.2.2.0.1:$0.0.0.1.$0.0.0.0">
            <div style="overflow:hidden;" data-reactid=".0.2.2.0.1:$0.0.0.1.$0.0.0.0.0">
                <a href="" target="_blank" class="item-pic" data-reactid=".0.2.2.0.1:$0.0.0.1.$0.0.0.0.0.0"><img src="` + item.img + `" data-reactid=".0.2.2.0.1:$0.0.0.1.$0.0.0.0.0.0.0"></a>
                <a href="" target="_blank" class="order_title JS_order_title" data-reactid=".0.2.2.0.1:$0.0.0.1.$0.0.0.0.0.2">` + item.commodity + `</a>
            </div>
        </div>
    </div>
</div>
<div class="fl" style="width:115px;font-weight:normal;text-align:center;" data-reactid=".0.2.2.0.1:$0.0.0.1.$0.1">` + item.count + `</div>
<div class="fl price" style="width:160px;line-height:15px;position:relative;top:39px;" data-reactid=".0.2.2.0.1:$0.0.0.1.$0.2"><span data-reactid=".0.2.2.0.1:$0.0.0.1.$0.2.0">` + item.money + `</span></div>
<div class="fl price" style="width:170px;" data-reactid=".0.2.2.0.1:$0.0.0.1.$0.4"><span class="price-to-align" data-reactid=".0.2.2.0.1:$0.0.0.1.$0.4.0">` + item.price + `</span></div>
</div>
`)
        }
    })
    $(".summary").html(`<div class="line line-text" data-reactid=".0.2.4.1.0.0"><span data-reactid=".0.2.4.1.0.0.0">共</span><span class="pink" style="color:#ed145b;" data-reactid=".0.2.4.1.0.0.1">` + count + `</span><span data-reactid=".0.2.4.1.0.0.2">件商品,总商品金额:</span><span class="pink sum" data-reactid=".0.2.4.1.0.0.3">¥` + money + `</span></div>
  <noscript data-reactid=".0.2.4.1.0.1:$0"></noscript><noscript data-reactid=".0.2.4.1.0.1:$1"></noscript><noscript data-reactid=".0.2.4.1.0.1:$2"></noscript>
  <div class="line" data-reactid=".0.2.4.1.0.1:$3">
      <div class="line-text" data-reactid=".0.2.4.1.0.1:$3.0"><span data-reactid=".0.2.4.1.0.1:$3.0.0">总运费</span><span data-reactid=".0.2.4.1.0.1:$3.0.1">:</span><span class="pink sum" data-reactid=".0.2.4.1.0.1:$3.0.2">¥0.00</span></div>
  </div>
  <div class="line need-pay" data-reactid=".0.2.4.1.0.2" style="margin-bottom: 42px;">
      <div class="line-text" data-reactid=".0.2.4.1.0.2.0"><span data-reactid=".0.2.4.1.0.2.0.0">应付总额:</span><span class="pink sum" data-reactid=".0.2.4.1.0.2.0.1">¥` + money + `</span></div>
  </div>
  <div class="confirm_pay main_content clearfix bottom" style="background:#fafafa;height:42px;" data-reactid=".0.2.4.1.0.3">
  
  <div class="submit_box clearfix" data-reactid=".0.2.4.1.0.3.2">
      <div class="fl price_box" style="position:relative;top:8px;" data-reactid=".0.2.4.1.0.3.2.0"><span data-reactid=".0.2.4.1.0.3.2.0.0">应付总额：</span><span class="price" data-reactid=".0.2.4.1.0.3.2.0.1"><span data-reactid=".0.2.4.1.0.3.2.0.1.0">¥</span><span data-reactid=".0.2.4.1.0.3.2.0.1.1">${money}</span></span>
      </div>
      <div class="fl" style="position:relative;top:10px;"><span style="cursor:pointer;font-weight:normal;font-size:18px;" class="submit_btn" data-reactid=".0.2.4.1.0.3.2.1.0" onclick=affirm()>确认交易</span></div>
  </div>
</div>
  `)
})

function affirm() {
    if ($("#textarea_addr").html() != "") {
        axios({
            method: "get",
            url: "http://127.0.0.1:8400/submit",

        }).then(response => {
            window.location = "./paying.html";
        })
    } else {
        alert("收获地址未填写");
    }
}


$("#wy_ad").click(function() {
    $("#wy_zz ").css("display", "block");
    $("#wy_yy ").css("display", "block");
})
$("#wy_delete").click(function() {
    $("#wy_zz").css("display", "none");
    $("#wy_yy ").css("display", "none");
})
$("#wy_delete2").click(function() {
    $("#wy_zz").css("display", "none");
    $("#wy_yy ").css("display", "none");
})
$("#wy_submit").click(function() {
    $("#wy_yy").css("display", "none");
    $("#wy_zz").css("display", "none");
    axios({
        method: "get",
        url: "http://127.0.0.1:8400/comf",
        params: {
            name: $("#wy_name").val(),
            phone: $("#wy_phone").val(),
            DA: $("#wy_DA").val()
        }
    }).then(response => {
        let html = response.data;
        console.log(html);
        html = `<span>收货人:${html.UserName}</span></br><span>手机号：${html.number}</span></br><span>详细地址：${html.detailed}</span>`
        $("#textarea_addr").html(html);
    })
})